package com.ruoyi.hotel.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hotel.domain.HlDevice;
import com.ruoyi.hotel.domain.HlRoomDevice;
import com.ruoyi.hotel.domain.dto.HlRoomDeviceDTO;
import com.ruoyi.hotel.domain.pojo.HlRoomDevicePojo;
import com.ruoyi.hotel.service.IHlRoomDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.error;

/**
 * 房间设备Controller
 * 
 * @author ruoyi
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/hotel/hlroomdevice")
public class HlRoomDeviceController extends BaseController
{
    @Autowired
    private IHlRoomDeviceService hlRoomDeviceService;


    /**
     * 查询房间设备列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlRoomDevice hlRoomDevice)
    {
        startPage();
        List<HlRoomDeviceDTO> list = hlRoomDeviceService.selectHlRoomDeviceList(hlRoomDevice);
        return getDataTable(list);
    }



    /**
     * 查询房间设备根据房间类型名
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:name')")
    @GetMapping("/name")
    public AjaxResult name(@RequestParam("roomTypeName") String roomTypeName)
    {

        return  hlRoomDeviceService.selectHlRoomDeviceByRoomTypeName(roomTypeName);

    }


    /**
     * 新增房间类型AndJson
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:add')")
    @Log(title = "房间设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addRoomTypeAndJson(@RequestBody HlRoomDevicePojo hlRoomDevicePojo)
    {
        return hlRoomDeviceService.addRoomTypeAndJson(hlRoomDevicePojo);
    }


    /**
     * 修改房间设备
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:edit')")
    @Log(title = "房间设备", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult updateRoomDevice(@RequestBody HlRoomDevicePojo hlRoomDevicePojo)
    {
        return hlRoomDeviceService.updateRoomDevice(hlRoomDevicePojo);

    }


    /**
     * 获取房间设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(hlRoomDeviceService.selectHlRoomDeviceById(id));
    }



    /**
     * 删除房间设备
     */
    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:remove')")
    @Log(title = "房间设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return hlRoomDeviceService.deleteHlRoomDeviceByIds(ids);
    }


//    /**
//     * 导出房间设备列表
//     */
//    @PreAuthorize("@ss.hasPermi('hotel:hlroomdevice:export')")
//    @Log(title = "房间设备", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, HlRoomDevice hlRoomDevice)
//    {
//        List<HlRoomDevice> list = hlRoomDeviceService.selectHlRoomDeviceList(hlRoomDevice);
//        ExcelUtil<HlRoomDevice> util = new ExcelUtil<HlRoomDevice>(HlRoomDevice.class);
//        util.exportExcel(response, list, "房间设备数据");
//    }


}
